package com.example.tcpTio.server;

import com.example.common.TioPacket;
import com.example.tioServer.ServerStarter;
import com.example.tioServer.handler.ServerHandlerBase;
import org.tio.core.ChannelContext;
import org.tio.core.Tio;
import org.tio.core.intf.Packet;

import java.io.IOException;

public class TioServerStarter {
    /**
     * 启动程序入口
     */
    public static void main(String[] args) throws IOException {

        ServerStarter server=new ServerStarter(10000);
        server.setServerListener(new ServerHandlerBase() {
            @Override
            public void handler(Packet packet, ChannelContext channelContext) throws Exception {
                TioPacket helloPacket = (TioPacket) packet;
                byte[] body = helloPacket.getBody();
                if (body != null) {
                    String message = new String(body, TioPacket.CHARSET);
                    System.out.println("收到消息：" + message);

                }
            }
        });
        server.start();
    }

}
